Computers / Programming / Projects / Code Formatter / Helper Classes

These classes don’t store any data and are simply used to hold helper methods.

Code

FormatHelper.h / FormatHelper.cpp

FormatHelper.h

h type icon
Type: Header file
Language: C++
FormatHelper.h

FormatHelper.cpp

cpp type icon
Type: Code file
Language: C++
FormatHelper.cpp

Contains a set of functions which help with parsing the file.

The GetWord(std::string line, int pos, std::regex regEx) method retrieves a word from line. It starts at pos and loops through line until it finds a character that doesn’t match the regEx. It then returns the contents of line starting at pos and going up to the character that doesn’t match.

The IsMatch(std::string line, std::string str, int lineStartPos, std::regex nextCharRegEx) method tests to see if the str string appears at the point in line specified by lineStartPos. If first checks if the line is long enough to contain str and then does a comparison to see if str matches the line. If str is there it then tests the character after the string, if there is one, to see if it matches the nextCharRegEx regular expression. If str is in the line and the next character doesn’t match it returns true, otherwise it returns false. The regular expression check is there to prevent grabbing part of a larger sequence.

The EscapeCount(std::string line, std::string escape, int lineStartPos) method starts at the point in line specified by lineStartPos and counts how many times the escape string appears before that point. It then returns the count. If the escape string is blank it just returns 0 to account for languages that don't have escapes sequences defined.

PhpHelper.h / PhpHelper.cpp

PhpHelper.h

h type icon
Type: Header file
Language: C++
PhpHelper.h

PhpHelper.cpp

cpp type icon
Type: Code file
Language: C++
PhpHelper.cpp

Contains a set of methods which mimic those available in php to make porting between C++ and php easier.

The htmlspecialchars(std::string input) method is a port of the php htmlspecialchars function. It loops through the input string and produces an output string with all HTML special characters replaced with their respective escapes sequences. For example a < in the input string would become &lt; in the output string.

The explode(std::string delimiter, std::string str) method is a port of the php explode function. It finds instances of the delimiter string in str and produces a vector of strings split at those points. The delimiter is not included in the vector of split strings.